import 'package:flutter/material.dart';
import 'package:flutter_ncsjqz_getx/constant/constant.dart';
import 'package:flutter_ncsjqz_getx/widget/app_bar_widget.dart';
import 'package:flutter_ncsjqz_getx/widget/gradient_button.dart';
import 'package:flutter_ncsjqz_getx/widget/ink_widget.dart';
import 'package:get/get.dart';

import '../user_info_setting_logic.dart';
import 'set_nike_name_logic.dart';

/// <summary>
/// todo: 设置 昵称、兴趣、个人简介
/// author：zwb
/// dateTime： 2021/11/11 17:37
/// filePath： lib/page/my/userinfo_setting/set_name/set_nike_name_view.dart
/// desc:
/// <summary>
enum SNM{
  nikeName,
  loveGood,
  brief,
}
class SetNikeNamePage extends StatefulWidget {
  final SNM? type;
  final String? title;
  final String? value;
  SetNikeNamePage({ this.type: SNM.nikeName, this.title:'', this.value:''});
  @override
  _SetNikeNamePageState createState() => _SetNikeNamePageState();
}

class _SetNikeNamePageState extends State<SetNikeNamePage> {
  final logic = Get.put(SetNikeNameLogic());

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    logic.setName(widget.value);
  }
  @override
  Widget build(BuildContext context) {

    double height = widget.type == SNM.brief ? 75:50;
    int maxLines = widget.type == SNM.brief ? 2 : 1;
    bool off = widget.type == SNM.brief ? true : false;

    return Scaffold(
      backgroundColor: Colors.white,
      appBar: appBarWidget(title: widget.title),
      body: Column(
        children: [
          Container(
            height: height,
            padding: EdgeInsets.symmetric(horizontal: 15,),
            decoration: BoxDecoration(
              border: Border(bottom: BorderSide(color: Colors.grey.shade200,))
            ),
            child: TextField(
              controller: logic.textEditingController,
              maxLines: maxLines,
              decoration: InputDecoration(
                border: InputBorder.none,
                hintText: "点击输入${widget.title}",
                suffixIcon: Offstage(
                  child: InkWidget.imgAsset("rem.png",onTap: (){
                    logic.textEditingController.clear();
                  },padding: EdgeInsets.symmetric(vertical: 15)),
                  offstage: off,
                ),
              ), 
            ),
          ),

          SizedBox(height: 40,),

          SizedBox(
            width: Get.width * 0.7,
            height: 40,
            child: gradientButton("保 存",circular: 40,onTap: () async{
              Map<String,dynamic> map = {"id":Constant.userDetailData!.id,};
              if(widget.type == SNM.nikeName){
                map["nickName"] = logic.textEditingController.value.text;
              }
              if(widget.type == SNM.loveGood){
                map["hobby"] = logic.textEditingController.value.text;
              }
              if(widget.type == SNM.brief){
                map["selfIntroduction"] = logic.textEditingController.value.text;
              }
              Get.put(UserInfoSettingLogic()).setUserInfo(map);
              Get.back( result: logic.textEditingController.value.text);
            }),
          ),
        ],
      ),
    );
  }

  @override
  void dispose() {
    Get.delete<UserInfoSettingLogic>();
    Get.delete<SetNikeNameLogic>();
    super.dispose();
  }
}